package com.zztl.infiniteBand.presenter

import android.content.Context
import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.MsgBean
import com.zztl.infiniteBand.model.NoticeCountBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.ui.view.mvpview.MessageView
import java.util.*

/**
 * @desc
 * @auth ${user}
 * @time 2018/6/14  10:15
 */
class MessagePresenter : BasePresenter<MessageView>() {
    fun getMessage(context: Context) {
        val params = HashMap<String, String>()
        params["limit"] = "5"
        params["page"] = "0"
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!!!.apiService
                .getMessage(DataConverter.instance.toJson(params)))
                .subscribe(object : FilterSubscriber<MsgBean>(context) {
                    override fun success(msgBean: MsgBean) {
                        view!!.getMseeageSuccess(msgBean)
                    }


                }))
    }

    fun getNoticeCount(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!!!.apiService
                .getMessageNoticeCount(DataConverter.instance.toJson("")))
                .subscribe(object : FilterSubscriber<NoticeCountBean>(context) {
                    override fun success(msgCountBean: NoticeCountBean) {
                        view!!.getMseeageCountSuccess(msgCountBean)
                    }


                }))
    }
}
